<?php

include "includes/bootstrap.php";

if (isset($_POST['add_link'])) {
	if (filter_link($_POST['title'], $_POST['url']) == 1 && checkLength($_POST['title'])) {
		$link = new Link();
		$link->add($_POST['title'], $_POST['url'], $_POST['category'], $_POST['description']);
		echo breakline("Link <b>{$_POST['title']}</b> successfully added.");
	}
}

if (isset($_POST['add_category'])) {
	if(checklength($_POST['category_name'])) {
		add_category($_POST['category_name']);
		echo breakline("Category <strong>{$_POST['category_name']}</strong> successfully added.");
	}
	//list_category_options();
}

if(isset($_POST['load_category_selectbox'])) {
	$list = new Lister();
	$list->category_selectbox("id", "category");
}

if(isset($_POST['list_categories'])) {
	$list = new Lister();
	$list->categories();
}

if(isset($_POST['load_link_list'])) {
	$list = new Lister();
	$list->links_for_category();
}

if(isset($_POST['list_links_for_category'])) {
	$list = new Lister();
	$list->links_for_category("name", $_POST['list_links_for_category']);
}

if (isset($_POST['delete_link'])) {
	delete_link($_POST['link_id']);
}

if (isset($_REQUEST['update_list'])) {
	//echo "<option>la</option>";
}

?>